import pygame

SCREEN_SIZE = (400, 600)


class GameSprite(pygame.sprite.Sprite):
    def __init__(self, file_name, speed=1):
        super().__init__()
        self.image = pygame.image.load(file_name)
        self.rect = self.image.get_rect()
        self.speed = speed

    def update(self):
        self.rect.y += self.speed


class Plane(GameSprite):
    def __init__(self, file_name, speed=1):
        super().__init__(file_name, speed)
        self.rect.centerx = SCREEN_SIZE[0]//2
        self.rect.bottom = SCREEN_SIZE[1]
    # def update(self):
    #     self.rect.x +=self.speed

class Game:
    def __init__(self):
        self.is_loop = True

    def main(self):
        pygame.init()
        self.screen = pygame.display.set_mode(SCREEN_SIZE)
        pygame.display.set_caption("飞机大战")

        while self.is_loop:
            self.screen.fill((0,255,0))
            self.event_handler()
            self.create_sprites()
            self.update_sprites()
            pygame.display.update()
        pygame.quit()

    def event_handler(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.is_loop = False

    def create_sprites(self):
        self.hero = Plane('./image/me1.png')
        self.group_hero = pygame.sprite.Group(self.hero)

    def update_sprites(self):
        self.group_hero.update()
        self.group_hero.draw(self.screen)


g = Game()
g.main()
